package com.example.shiwuyouproject.ui.fragment.my.activity.viewmodel

import androidx.lifecycle.MutableLiveData
import com.example.shiwuyouproject.base.BaseViewModel
class ChangePasswordViewModel : BaseViewModel() {
    private val loginRepository by lazy { RetrofitClient.getApiService() }
    val myCodeState = MutableLiveData<Boolean>()

    /**
     * 获取验证码
     */
    fun smsSend(mobile: String) {
        launch(
            block = {
                val codeStatus = loginRepository.smsSend(mobile, "resetpwd")
                myCodeState.value = codeStatus.success()
                messageStatus.value = codeStatus.message()
            },
            error = {
                myCodeState.value = false
            },
            cancel = {

            },
            showErrorToast = false
        )
    }

    val getUserResetpwdState = MutableLiveData<Boolean>()

    /**
     * 忘记/修改密码
     */
    fun getUserResetpwd(mobile: String, newpassword: String, captcha: String) {
        launch(
            block = {
                val codeStatus = loginRepository.getUserResetpwd(mobile, newpassword, captcha)
                getUserResetpwdState.value = codeStatus.success()
                messageStatus.value = codeStatus.message()
            },
            error = {
                getUserResetpwdState.value = false
            },
            cancel = {

            },
            showErrorToast = false
        )
    }
}